define(window.backboneCommon.getViewDefine("finance.customerConsume"), function ($,require,Collection,tpl) {
    var defaultsOptions={};
    var pagePrivate = {
        getDefaults :function () {
            return defaultsOptions
        },
        getOptions : function (options) {
            options=$.ExtCommon.isCheckEmpty(options)?{}:options;
            return $.ExtCommon.initMergeJson(this.getDefaults(),options);
        }
    };
    var backboneView= Backbone.View.extend({
        events: {
        },
        initialize: function () {
            this.listenTo(this.model, 'bind:CustomerListConsume', this.bindList);
            this.render();
        },
        render:function(){
            var templateHtml=_.template(tpl);
            this.$el.html(templateHtml());
            return this;
        },
        initMain:function(options){
            this.elementModel={
                table:$("#tb_listCustomerConsume")
            };
            this.extObject={};
            this.pageData={initPage:false};
            this.pageOptions=$.ExtCommon.initMergeJson(pagePrivate.getOptions(),options);
            this._initTimeRange();
        },
        initPage:function(){
            if(!this.pageData.initPage){
                this.pageData.initPage=true;
                this._initPageList();
            }
        },
        _initTimeRange:function () {
            var self=this;
            self.extObject.timeRange=$("#search_timeRange_customerConsume").ExtDatePicker({type:"range",
                startValue:$.ExtMoment.initSubtract(6, "days"),endValue:$.ExtMoment.initFormat(),
                changeCallback: function () {self.refreshList()}
            });
        },
        getTimeRangeValue:function(){
            var arrTime =this.extObject.timeRange.getValue();
            return {startTime:arrTime[0],endTime:arrTime[1]}
        },
        _initPageList: function () {
            var self=this;
            self.extObject.table=self.elementModel.table.ExtDataTable({
                columns: [
                    {data:"time", class: "w-200"},
                    {data:"out",class: "w-200 num-float2"},
                    {data:"surplus",class: "w-200 num-float2"},
                    {data:"remark", class: ""}
                ],
                infoExt:{
                    ajaxDataPara:function(){
                        var param= {};
                        var timeRange=self.getTimeRangeValue();
                        param= $.ExtCommon.initMergeJson(param,timeRange);
                        return param;
                    },
                    ajaxWholeCallback:function(param){self.collection.getCustomerListConsume(param)}
                },
                createdRow: function () {},
                drawCallback: function () {
                    $.ExtNumeric.initAll();
                }
            });
        },
        bindList:function(){
            var data=this.model.get("dataCustomerListConsume");
            this.extObject.table.ajaxWholeRefreshData(data);
        },
        refreshList: function () {this.extObject.table.refresh()}
    });
    var viewModel=function(options){
        this.collection= new Collection();
        this.model=this.collection.model;
        this.view=new backboneView({el: options.pElement,collection:this.collection,model:this.model});
        this.view.initMain(options);
    };
    viewModel.prototype={
        init:function () {
            this.view.initPage();
        }
    };
    return viewModel;
});